<?php
namespace app\admin\controller;

use app\common\cache\car\ICarBrandCache;
use app\common\cache\car\ICarConfigCache;
use app\common\cache\car\ICarModelCache;
use app\common\controller\AdminBaseController;
use app\common\enum\HolderType;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\IRequest;

class UserCar extends AdminBaseController{

    /**
     * @功能：用户车辆信息
     * @开发者：cxl
     * @return string
     */
    public function user_car_list(){
        //接收参数
        $user_id = IRequest::get('user_id');
        $car_brand_id = IRequest::get('car_brand_id');
        $car_model_id = IRequest::get('car_model_id');
        $car_config_id = IRequest::get('car_config_id');

        //取得代理商数据
        $car_brand_list = ICarBrandCache::getList();

        //取得代理商数据
        $car_model_list = ICarModelCache::getList();

        //取得代理商数据
        $car_config_list = ICarConfigCache::getList();

        //设置查询条件user_car_list
        $where = null;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($car_brand_id)) $where['car_brand_id'] = $car_brand_id;
        if(!empty($car_model_id)) $where['car_model_id'] = $car_model_id;
        if(!empty($car_config_id)) $where['car_config_id'] = $car_config_id;
        $user_car_list = IDb::getInstance('asset_car')->setDbWhere($where)->setDbOrder("user_car_id desc")->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("car_brand_id",$car_brand_id);
        $this->assign("car_model_id",$car_model_id);
        $this->assign("car_config_id",$car_config_id);
        $this->assign("car_brand_list",$car_brand_list);
        $this->assign("car_model_list",$car_model_list);
        $this->assign("car_config_list",$car_config_list);
        $this->assign("user_car_list",$user_car_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：用户车辆信息历史
     * @开发者：cxl
     * @return string
     */
    public function user_car_info(){
        //接收参数
        $user_car_id = IRequest::get('user_car_id',IRequest::NOT_EMPTY,"用户车辆编号不能为空！");

        //取得代理商数据
        $car_brand_list = ICarBrandCache::getList();

        //取得代理商数据
        $car_model_list = ICarModelCache::getList();

        //取得代理商数据
        $car_config_list = ICarConfigCache::getList();

        //设置查询条件
        $where['user_car_id'] = $user_car_id;
        $user_car_info = IDb::getInstance('asset_car')->setDbWhere($where)->row();

        if($user_car_info['holder_type'] == HolderType::Other){
            $user_car_info['holder'] = $user_car_info['holder_name'];
        }else{
            $user_car_info['holder'] = get_enum_name('holder_type',$user_car_info['holder_type']);
        }
        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("car_brand_list",$car_brand_list);
        $this->assign("car_model_list",$car_model_list);
        $this->assign("car_config_list",$car_config_list);
        $this->assign("user_car_info",$user_car_info);

        //渲染模板输出
        return view();
    }
}
